﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

namespace DoAnGiaPhaVersion1._0
{
    public class UtilitiesGUI
    {
        public static void showColumn(DataGridView dg, string[] columnShow, string[] headerText)
        {
            for (int i = 0; i < dg.ColumnCount; i++)
            {
                dg.Columns[i].Visible = false;
            }
            for (int i = 0; i < columnShow.Length; i++)
            {
                dg.Columns[columnShow[i]].Visible = true;
                dg.Columns[i+1].HeaderText = headerText[i];                
            }
            dg.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dg.BorderStyle = BorderStyle.None;            
            dg.SelectionMode = DataGridViewSelectionMode.FullRowSelect;            
        }
        
        public static string openFile()
        {            
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            string path="";
            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "Jpeg files (*.jpeg)|*.jpeg|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    
                    path = openFileDialog1.FileName;
                    MessageBox.Show(path);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return path;
        }
        public static void copyFile(string path, int mathanhvien)
        {
            string path2 = @"..\images\";
            try
            {
                string oldPath = path;
                string newpath = path2;
                string newFileName = "avatar_"+mathanhvien;
                FileInfo f1 = new FileInfo(oldPath);
                if (f1.Exists)
                {
                    if (!Directory.Exists(newpath))
                    {
                        Directory.CreateDirectory(newpath);
                    }
                    File.Copy(path, path2+newFileName+f1.Extension, true);
                }
            }

            catch
            {
                MessageBox.Show("Loi con me no roi!!");
            }
        }
    }
}
